package com.qf.six.ssm.service.order.impl;

import com.github.pagehelper.PageHelper;
import com.qf.six.ssm.commen.request.RequestParams;
import com.qf.six.ssm.commen.utils.RandomUtils;
import com.qf.six.ssm.commen.vo.OrderVo;
import com.qf.six.ssm.entity.Order;
import com.qf.six.ssm.mapper.order.OrderMapper;
import com.qf.six.ssm.service.order.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service("orderService")
public class OrderServiceImpl implements OrderService {
    @Resource
    OrderMapper orderMapper;
    @Override
    public List<OrderVo> info(RequestParams params) {
        PageHelper.startPage(params.getPage(), params.getSize());
        List<OrderVo> info = orderMapper.info();
        return info;
    }

    @Override
    public List<OrderVo> selectOrderByTid(RequestParams params, Integer tid) {
        PageHelper.startPage(params.getPage(), params.getSize());
        return orderMapper.selectOrderByTid(tid);
    }

    @Override
    public int insertOrder(Order order) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        String date = df.format(new Date());
        order.setNumber(RandomUtils.random()+date);
        return orderMapper.insertOrder(order);
    }

    @Override
    public int deleteOrder(Integer oid) {
        return orderMapper.deleteOrder(oid);
    }

    @Override
    public int putOrder(Order order) {
        return orderMapper.putOrder(order);
    }

    @Override
    public int fakeDelete(Order order) {
        Integer count = orderMapper.fakeDelete(order);

        return count;
    }

    @Override
    public List<OrderVo> selectOrderByUid(Integer uid) {
        return orderMapper.selectOrderByUid(uid);
    }
}
